﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace OneWorks.Web.Common
{
    public class Tree
    {
        /// <summary>
        /// An identity value bind to the node.
        /// </summary>
        [JsonProperty(PropertyName = "id")]
        public object ID { get; set; }

        /// <summary>
        /// Text to be showed.
        /// </summary>
        [JsonProperty(PropertyName = "text")]
        public string Text { get; set; }

        /// <summary>
        /// The css class to display icon.
        /// </summary>
        [JsonProperty(PropertyName = "iconCls")]
        public string IconCls { get; set; }

        /// <summary>
        ///  Whether the node is checked.
        /// </summary>
        [JsonProperty(PropertyName = "checked")]
        public string Checked { get; set; }

        /// <summary>
        /// The node state, 'open' or 'closed'.
        /// </summary>
        [JsonProperty(PropertyName = "state")]
        public string State { get; set; }

        /// <summary>
        /// Custom attributes bind to the node.
        /// </summary>
        [JsonProperty(PropertyName = "attributes")]
        public Dictionary<string, object> Attributes { get; set; }

        [JsonProperty(PropertyName = "children")]
        public List<Tree> Childrens { get; set; }

        [JsonProperty(PropertyName = "parent")]
        public object Parent { get; set; }
    }

    public enum NodeType
    {
        Id,
        Text,
        IconCls,
        Checked,
        State,
        Attribute,
        Parent,
        Columns
    }

    public class TreeAttribute : Attribute
    {
        public NodeType NodeType { get; private set; }

        public TreeAttribute(NodeType nodeType)
        {
            NodeType = nodeType;
        }
    }
}
